/********************************************

@Author :yinjinlin<yinjinlin_uplook@163.com>
@Time : 2021/2/1 17:49
@Description:

*********************************************/
package main

import (
	"context"
	"strconv"
	"strings"

	"git.900sui.cn/kc/base/utils"
	"git.900sui.cn/kc/kcgin"
	"git.900sui.cn/kc/kcgin/logs"
	"git.900sui.cn/kc/rabbitmq"
	"git.900sui.cn/kc/rpcinterface/client/comtreeData"
	"git.900sui.cn/kc/rpcinterface/client/dataVisualization"
	comtreeData2 "git.900sui.cn/kc/rpcinterface/interface/comtreeData"
	dataVisualization2 "git.900sui.cn/kc/rpcinterface/interface/dataVisualization"
	"github.com/streadway/amqp"
)

func main() {
	rpcVisualization := new(dataVisualization.BusRiskRank).Init()
	rpcMerchantSecurityCode := new(comtreeData.MerchantSecurityCode).Init()
	logs.Info("Environment Variable:MSF_ENV:", kcgin.KcConfig.RunMode)
	new(utils.KcLog).GetInstance(kcgin.AppConfig.String("dataVisualization.log.riskBusSafeCode"))

	err := rabbitmq.Rabbitmq.Consume(kcgin.AppConfig.String("dataVisualization.queue.riskBusSafeCode"), func(msg amqp.Delivery) {
		dataStr := string(msg.Body)
		logs.Info("dataStr:", dataStr)
		dataSlice := strings.Split(dataStr, "_")
		if len(dataSlice) >= 7 {
			//riskBusId_风险状况值_安全码颜色值_省id_市id_区id_街道id_领域id_行业id_商圈id_综合体id_资金管理方式_风险评分
			//89379_2_2_25_321_2717_3429_7_199_145_3704_1
			logs.Info("run:", 1)
			sData := &dataVisualization2.ArgsBusRisRandSafeCode{}
			sData.RiskBusId, _ = strconv.Atoi(dataSlice[0])
			sData.Rank, _ = strconv.Atoi(dataSlice[1])
			sData.SafeCodeColor, _ = strconv.Atoi(dataSlice[2])
			sData.Pid, _ = strconv.Atoi(dataSlice[3])
			sData.Cid, _ = strconv.Atoi(dataSlice[4])
			sData.Did, _ = strconv.Atoi(dataSlice[5])
			sData.Tid, _ = strconv.Atoi(dataSlice[6])
			sData.DistrictId, _ = strconv.Atoi(dataSlice[9])
			sData.SyntId, _ = strconv.Atoi(dataSlice[10])
			sData.SyntId, _ = strconv.Atoi(dataSlice[10])
			sData.RankScore = dataSlice[12]

			var reply bool
			if err := rpcVisualization.UpdateBusRisRandSafeCode(context.Background(), sData, &reply); err != nil {
				utils.Logerr.Printf("更改商户风险等级和安全码信息失败，riskBusId：【%s】失败信息：%s\n", dataSlice[0], err.Error())
			}
			logs.Info("run:", 2)
			//MerchantSecurityCode接口数据拼接
			data := &comtreeData2.ArgsMerchantSecurityCode{}
			data.RiskBusId, _ = strconv.Atoi(dataSlice[0])
			data.Rank, _ = strconv.Atoi(dataSlice[1])
			data.SecurityCodeStatus, _ = strconv.Atoi(dataSlice[2])
			data.Pid, _ = strconv.Atoi(dataSlice[3])
			data.Cid, _ = strconv.Atoi(dataSlice[4])
			data.Did, _ = strconv.Atoi(dataSlice[5])
			data.Tid, _ = strconv.Atoi(dataSlice[6])
			data.IndustryId, _ = strconv.Atoi(dataSlice[7])
			data.BindId, _ = strconv.Atoi(dataSlice[8])
			data.DistrictId,_=strconv.Atoi(dataSlice[9])//商圈
			data.SyntId,_=strconv.Atoi(dataSlice[10])//综合体
			data.FundMode, _ = strconv.Atoi(dataSlice[11])//资金管理方式
			var replys bool
			if err := rpcMerchantSecurityCode.AddMerchantSecurityCodeRpc(context.Background(), data, &replys); err != nil {
				utils.Logerr.Printf("comtreeData.MerchantSecurityCode 存储商户风险等级和安全码信息失败，riskBusId：【%s】失败信息：%s\n", dataSlice[0], err.Error())
			}
		}
	})

	if err != nil {
		utils.Logerr.Printf("更改商户风险等级和安全码信息错误，错误信息：%s\n", err.Error())
	}
}
